package cn.initcap.concurrency.concurrency.concurrent;

import cn.initcap.concurrency.concurrency.ThreadPoolCreatHelper;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import lombok.extern.slf4j.Slf4j;

/**
 * J.U.C是java.util.concurrent的缩写，并发容器。
 *
 * @author initcap
 * @date Created in 2018/6/16 PM3:38.
 */
@Slf4j
public class CopyOnWriteArraySetExample {

    /**
     * 总请求数
     */
    private static final int CLIENT_TOTAL = 5000;

    /**
     * 同时并发执行的线程数
     */
    private static final int THREAD_TOTAL = 200;

    private static Set<Integer> set = new CopyOnWriteArraySet<>();

    public static void update(int i) {
        set.add(i);
    }

    public static void main(String[] args) throws Exception {
        ThreadPoolCreatHelper.threadFinalCountParam(CLIENT_TOTAL, THREAD_TOTAL,
                CopyOnWriteArraySetExample.class, "update",
                "CopyOnWriteArraySetExample");
        log.info("size:{}", set.size());
    }

}
